//------------------------------------------------------------------------------
// <copyright file="WinRtSocketListener.h" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

#pragma once

#ifndef USE_RAPIDJSON

#include <ppltasks.h>
#include <vector>
#include <concrt.h>
#include "WinRtStringSocket.h"
#include "RpcErrorCodes.h"
#include "RpcChannelListener.h"

// Forward declaration of the Unit Test class so that we can identify it as a friend.  It needs
// to be a friend so that it can access the private "Reset" method.
namespace Microsoft { namespace Internal { namespace GamesTest { namespace Rpc { namespace Server { namespace Ut
{
	class WinRtSocketListenerTests;

}}}}}}

namespace Microsoft { namespace Internal { namespace GamesTest { namespace Rpc { namespace Server
{
	using namespace Windows::Foundation;
	using namespace Windows::Networking::Sockets;
	using namespace concurrency;
	using namespace std;

	/// <summary>
	/// This class listens for incoming socket connections and data from clients.
	/// </summary>
	class WinRtSocketListener : public RpcChannelListener
	{
	private:
		StreamSocketListener^ m_systemSocketListener;
		EventRegistrationToken m_socketConnectedToken;

	public:
		/// <summary>
		/// Initializes a new instance of the WinRtSocketListener class.
		/// </summary>
		WinRtSocketListener();

	protected:
		/// <summary>
		/// Starts listening for incoming sockets and data.
		/// </summary>
		virtual GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT StartImpl(int port);

		/// <summary>
		/// Stops listening for incoming sockets and data.
		/// </summary>
		virtual GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT StopImpl();

		/// <summary>
		/// Binds listener to a port.
		/// </summary>
		virtual void BindEndpoint(Platform::String^ port);

	private:
		WinRtSocketListener(const WinRtSocketListener&) { }

		void OnWinRtSocketConnected(StreamSocketListener^ sender, StreamSocketListenerConnectionReceivedEventArgs^ args);
	};

}}}}}

#endif // _DURANGO